package com.web.portal.utils;

import org.apache.shiro.crypto.hash.SimpleHash;

import java.util.UUID;

public class ShiroUtil {
    /**
     * 生成32的随机盐值
     */
    public static String createSalt() {
        return UUID.randomUUID().toString()
                .replaceAll("-", "");
    }

    /**
     * 加盐加密
     *
     * @param srcPwd    原始密码
     * @param saltValue 盐值
     */
    public static String salt(Object srcPwd, String saltValue) {
        return new SimpleHash("MD5", srcPwd,
                saltValue, 1024).toString();
    }

    public static void main(String[] args) {
//        String srcPwd = "201314520";
//        String saltValue = createSalt();
//        System.out.println("原始密码：" + srcPwd);
//        System.out.println("盐值：" + saltValue);
        System.out.println("密文：" + salt("string", "bd9f2e35767a4333806150eacd7e2571"));

    }
}
